//
//  HLHomeCellRetweetView.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/21.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLHomeCellRetweetView.h"
#import "HLHomeCellPicturesView.h"
#import <Masonry.h>
#import "HLStatuses.h"

@interface HLHomeCellRetweetView ()
//文本
@property (nonatomic,strong) UILabel *retweetcontentLabel;
//图片
@property (nonatomic,strong) HLHomeCellPicturesView *retweetPicturesView;

//记录当前底部约束
@property (nonatomic,strong) MASConstraint *retweetViewBottomConstraint;

@end

@implementation HLHomeCellRetweetView

- (instancetype)init
{
    self = [super init];
    if (self) {
        //设置界面
        [self setupUI];
    }
    return self;
}

//设置界面
- (void)setupUI {
    
    self.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
    //添加子控件
    [self addSubview:self.retweetcontentLabel];
    [self addSubview:self.retweetPicturesView];
    
    //设置约束
    //文本
    [self.retweetcontentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).offset(HomeCellMargin);
        make.right.equalTo(self).offset(- HomeCellMargin);
    }];
    //图片
    [self.retweetPicturesView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.retweetcontentLabel.mas_bottom).offset(HomeCellMargin);
        make.left.equalTo(self.retweetcontentLabel);
    }];
    //设置自身约束
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        self.retweetViewBottomConstraint = make.bottom.equalTo(self.retweetPicturesView).offset(HomeCellMargin);
    }];
}

//重写setter方法
- (void)setRetweetStatuses:(HLStatuses *)retweetStatuses {
    _retweetStatuses = retweetStatuses;
    //设置文本内容
    self.retweetcontentLabel.text = [NSString stringWithFormat:@"@%@ :%@",retweetStatuses.user.name,retweetStatuses.text];
    //设置图片
    self.retweetPicturesView.imageUrlArr = retweetStatuses.imageUrlArr;
    //移除原有约束
    [self.retweetViewBottomConstraint uninstall];
    //根据有没有图片来修改底部约束
    if (retweetStatuses.imageUrlArr == nil || retweetStatuses.imageUrlArr.count == 0) {
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.retweetViewBottomConstraint = make.bottom.equalTo(self.retweetcontentLabel).offset(HomeCellMargin);
        }];
    }else {
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.retweetViewBottomConstraint = make.bottom.equalTo(self.retweetPicturesView).offset(HomeCellMargin);
        }];
    }
}

#pragma mark - 懒加载
//文本
- (UILabel *)retweetcontentLabel {
    if (_retweetcontentLabel == nil) {
        _retweetcontentLabel = [[UILabel alloc] initWithTitle:nil withTitleFont:14 withTitleColor:[UIColor lightGrayColor]];
    }
    return _retweetcontentLabel;
}
//图片
- (HLHomeCellPicturesView *)retweetPicturesView {
    if (_retweetPicturesView == nil) {
        _retweetPicturesView = [[HLHomeCellPicturesView alloc] init];
        _retweetPicturesView.backgroundColor = [UIColor colorWithWhite:0.93 alpha:1];
    }
    return _retweetPicturesView;
}

@end
